package com.dexgdx.game.action.movement;

import com.dexgdx.game.Game;
import com.dexgdx.game.constants.EMoveStopCondition;
import com.dexgdx.game.structure.base.BaseRegion;
import com.dexgdx.game.structure.base.MobileObject;
import com.dexgdx.game.structure.projectile.DexMissileObject;
import com.dexgdx.game.util.pathcalc.DirectPathCalcSession;

public class DexMissileMovementAction extends MovementAction {
	
	private DexMissileObject dexMissileObject;
	
	public static DexMissileMovementAction create(MobileObject movingObject,
			BaseRegion initialTarget){
		DexMissileObject dexMissileObject = DexMissileObject.instanceFromRegion(movingObject);
		return new DexMissileMovementAction(dexMissileObject, initialTarget);
	}
	
	private DexMissileMovementAction(DexMissileObject dexMissileObject,
			BaseRegion initialTarget) {
		super(dexMissileObject, initialTarget, new DirectPathCalcSession());
		this.dexMissileObject = dexMissileObject;
	}

	@Override
	public void runNextStep() {
		super.runNextStep();
		if(!super.isFinishedCalculation()){
			dexMissileObject.setPooledEffectPosition();
		}
		else{
			dexMissileObject.setPooledEffectPositionInvisible();
		}
	}

	@Override
	public boolean isFinished() {
		boolean finished = super.isFinished();
		if(finished){
			Game.animationRunning = false;
			dexMissileObject.stopMoving();
		}
		return finished;
	}
	
	@Override
	protected EMoveStopCondition getStopCondition() {
		return EMoveStopCondition.WHEN_OVER;
	}
}
